<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Trans Type
 *
 * @author Massri
 */
class Application_Model_TransType {
    //put your code here
    
    private $_db;
    
    function __construct() {
        $registry = Zend_Registry::getInstance();
        $this->_db = $registry->database;
    }

    function addTransType($transTypeCode, $transTypeDesc){

        $data = array(
            'trans_type_code' => $transTypeCode,
            'trans_type_desc' => $transTypeDesc
        );
        
        $this->_db->insert('trans_type',$data);
        $id = $this->_db->lastInsertId();

        $result = array("trans_type_id" => $id);

        return $result;
    }

    function editTransType($transTypeId, $transTypeCode, $transTypeDesc) {
            
        $data = array(
            'trans_type_code' => $transTypeCode,
            'trans_type_desc' => $transTypeDesc
        );

        $where = array(
            'trans_type_id = ?' => $transTypeId
        );

        $this->_db->update('trans_type', $data, $where);

        $result = array("trans_type_id" => $transTypeId);

        return $result;
    }

    function delTransType($transTypeId) {

        $where = array(
            'trans_type_id = ?' => $transTypeId
        );

        $this->_db->delete('trans_type', $where);

        $result = array("trans_type_id" => $transTypeId);

        return $result;
    }

    function getTransType($sBy, $key, $start, $limit) {
        
        $select = $this->_db->select();
        $select->from('trans_type');
        $select->where( $sBy ." like '%$key%' ");
        $select->order( $sBy );
        $select->limit($limit, $start);

        $stmt = $select->query();
        $result = $stmt->fetchAll();

        return $result;
    }

    function transTypeList() {

        $select = $this->_db->select();
        $select->from('trans_type');
        $select->where( " is_display = 'Y' ");
        $select->order('trans_type_desc');

        $stmt = $select->query();
        $result = $stmt->fetchAll();


        return $result;


    }

    function transTypeListPPOB() {

        $select = $this->_db->select();
        $select->from('trans_type');
        $select->where( " is_display = 'Y' and is_external = 'Y' ");
        $select->order('trans_type_desc');

        $stmt = $select->query();
        $result = $stmt->fetchAll();


        return $result;


    }
}

?>
